<?php
namespace Home\Controller;

use Think\Controller;
class ModeController extends CommonController
{
	public function __construct()
  	{
    	parent::__construct();
    
  	}

	public function default_mode()
  	{
	   	$Mode = M("Mode");
	  	$result = $Mode->field("id, name, url ,pic,appid")->where("mode = 1 and status = 0 and is_delete = 0")->order('order_id')->select();
	  	$form = home_url();

	  	foreach($result as $k=>$v){
			if(!$v['pic']){
		  		foreach($form as $v1){
		    		if($v['url'] == $v1['route']){
		      			$result[$k]['pic'] = $v1['pic'];
		    		}
		  		}
			}
	  	}
		if (empty($result)) { 
	      return_data("error", "index.users.empty");
	    } else {
	      return_data("success", "index.users.success", $result);
	    }
  	}
  	public function preferred_mode()
  	{
	   	$Mode = M("Mode");
	  	$result = $Mode->field("id, name, url ,pic,appid")->where("mode = 2 and status = 0 and is_delete = 0")->order('order_id')->select();
 		$form = home_url();
	  	$list = [];
	  	
	  	foreach($result as $k=>$v){
			if(!$v['pic']){
		  		foreach($form as $v1){
		    		if($v['url'] == $v1['route']){
		      			$v['pic'] = $v1['pic'];
		    		}
		  		}
			}
			$list[floor($k/2)][] = $v;
	  	};
		if (empty($result)) {
	      return_data("error", "index.users.empty");
	    } else {
	      return_data("success", "index.users.success", $list);
	    }
  	}
 
}
